<!--
 * @Author: 龙雨欢 932838577@qq.com
 * @Date: 2023-10-06 11:59:39
 * @LastEditors: 龙雨欢 932838577@qq.com
 * @LastEditTime: 2023-10-20 15:51:17
 * @FilePath: \sxyd-vue\src\components\nenghao\enterprises.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div>
        <h3 style="text-align: center;">应税污染物和当量值</h3>
        <el-form :inline="true" style="background-color: #F7F7F7;">
            <el-form-item label="税目" class="zhaiItem">
                <el-select v-model="suimu" filterable placeholder="请选择税目" style="width: 100%" @change="changeSuimu($event)">
                    <el-option v-for="item in suimuData" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="分类">
                <el-select v-model="fenlei" filterable placeholder="请选择分类" style="width: 100%"
                    @change="changeFenlei($event)">
                    <el-option v-for="item in fenleiData" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="污染物">
                <el-select v-model="wuranwu" filterable placeholder="请选择污染物" style="width: 100%"
                    @change="changeWuranwu($event)">
                    <el-option v-for="item in wuranwuData" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="细化" v-show="isXihua" class="zhaiItem">
                <el-select v-model="xihua" filterable placeholder="请选择细化" style="width: 100%" @change="changeXihua($event)">
                    <el-option v-for="item in xihuaData" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="单位" v-show="isUnit" class="zhaiItem">
                <el-select v-model="dangliangunit" filterable placeholder="请选择单位" style="width: 100%"
                    @change="changeUnit($event)">
                    <el-option v-for="item in unitData" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item :label="'污染物排放量(' + paifangliangdanwei + ')'">
                <el-input v-model="paifangliang" oninput="value=value.replace(/[^0-9.]/g,'')"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" plain @click="jisuan">计算纳税额</el-button>
            </el-form-item>
            <el-form-item :label="'应纳税额(' + nasuidanwei + '):'" prop="nasuie" class="nasui">
                <span class="nasuispan">{{ nasuie }}</span>
            </el-form-item>
        </el-form>
        <el-tag type="danger" class="tag" v-show="isbeizhu"> {{ beizhu }}</el-tag>
    </div>
</template>

<script>
export default {
    name: 'enterprises',
    data() {
        return {
            suimu: '',
            fenlei: '',
            wuranwu: '',
            xihua: '',
            dangliangunit: '',
            paifangliang: '',
            suimuData: [{
                label: '大气污染物',
                value: '大气污染物'
            }, {
                label: '水污染物',
                value: '水污染物'
            }, {
                label: '固体废物',
                value: '固体废物'
            }, {
                label: '噪声污染',
                value: '噪声污染'
            }],
            fenleiData: [],
            fenleiDatadaqi: [],
            fenleiDatashui: [],
            fenleiDataguti: [],
            fenleiDatazaosheng: [],
            wuranwuData: [],
            xihuaData: [],
            unitData: [{
                label: '床',
                value: '床'
            }, {
                label: 't污水',
                value: 't污水'
            }],
            isXihua: false,
            isUnit: false,
            nasuie: null,
            obj: {},
            paifangliangdanwei: 't',
            nasuidanwei: '元',
            beizhu: '',
            isbeizhu: true,
            isUnit: false,
            unitObjData: []
        }
    },
    methods: {
        changeSuimu(e) {
            if (e == '水污染物') {
                this.fenleiData = this.fenleiDatashui
            } else if (e == '固体废物') {
                this.fenleiData = this.fenleiDataguti
            } else if (e == '噪声污染') {
                this.fenleiData = this.fenleiDatazaosheng
            } else if (e == '大气污染物') {
                this.fenleiData = [{
                    label: '暂无分类',
                    value: '暂无分类'
                }]
                this.changeFenlei('暂无分类')
            }
            this.fenlei = ''
            this.wuranwu = ''
            this.xihua = ''
        },
        async changeFenlei(e) {
            if (this.fenlei == '暂无分类') {
                this.fenlei = ''
            }
            let data = []
            const { data: res } = await this.$http.post('/v1.0/resultIntegration/rule/yswrwhdlzb/findPages', {
                sm: this.suimu,
                fl: this.fenlei,
                wrw: '',
                pageNumber: 1,
                pageSize: 9999,
                xh: '',
            })
            for (let i in res.data.result) {
                data.push(res.data.result[i].wrw)
            }
            data = Array.from(new Set(data))
            console.log(data)
            this.wuranwuData = []
            if (data[0] != null) {
                this.wuranwu = ''
            } else {
                this.wuranwu = '不选择'
                this.obj = res.data.result[0]
                return;
            }
            for (let j in data) {
                this.wuranwuData.push({
                    label: data[j],
                    value: data[j]
                })
            }
        },
        async changeWuranwu(e) {
            const { data: res } = await this.$http.post('/v1.0/resultIntegration/rule/yswrwhdlzb/findPages', {
                sm: this.suimu,
                fl: this.fenlei,
                wrw: this.wuranwu,
                pageNumber: 1,
                pageSize: 9999,
                xh: '',
            })
            if (res.data.result.length > 1) {
                this.xihuaData = []
                this.isXihua = true;
                let dataxh = []
                for (let i in res.data.result) {
                    dataxh.push(res.data.result[i].xh)
                }
                dataxh = Array.from(new Set(dataxh))
                for (let j in dataxh) {
                    this.xihuaData.push({
                        label: dataxh[j],
                        value: dataxh[j]
                    })
                }
            } else {
                this.isXihua = false
                this.obj = res.data.result[0]
                this.paifangliangdanwei = res.data.result[0].srzdwl
            }
        },
        async changeXihua(e) {
            const { data: res } = await this.$http.post('/v1.0/resultIntegration/rule/yswrwhdlzb/findPages', {
                sm: this.suimu,
                fl: this.fenlei,
                wrw: this.wuranwu,
                pageNumber: 1,
                pageSize: 9999,
                xh: this.xihua,
            })
            if (res.data.result.length > 1) {
                this.isUnit = true
                this.unitObjData = res.data.result
            } else {
                this.isUnit = false
                this.obj = res.data.result[0]
            }
        },
        changeUnit(e) {
            for (let i in this.unitObjData) {
                if (this.unitObjData[i].dldw == e) {
                    this.obj = this.unitObjData[i]
                }
            }
        },
        jisuan() {
            if (this.wuranwu == '不选择') {
                this.nasuie = Number(this.paifangliang) * Number(this.obj.se)
                this.nasuidanwei = this.obj.sedw
                this.paifangliangdanwei = this.obj.srzdwl
                this.beizhu = '备注：' + this.obj.bz;
                return;
            }
            if (this.paifangliang && this.obj) {
                console.log(this.obj)
                if (this.obj.gslb == '1000' || this.obj.gslb == '1') {
                    this.nasuie = ((Number(this.paifangliang) * Number(this.obj.gslb) )/ Number(this.obj.wrwdl)* Number(this.obj.se)).toFixed(3)
                    this.paifangliangdanwei = this.obj.srzdwl
                    this.nasuidanwei = this.obj.sedw
                } else if (this.obj.gslb == '0') {
                    this.nasuie = Number(this.paifangliang) * Number(this.obj.se)
                    this.paifangliangdanwei = this.obj.srzdwl
                    this.nasuidanwei = this.obj.sedw
                }
                this.beizhu = '备注：' + this.obj.bz;
            } else {
                return this.$message.error('请输入排放量或选择污染物')
            }
        }
    },
    async created() {
        const { data: res } = await this.$http.get('/v1.0/resultIntegration/rule/yswrwhdlzb/findAll', {
            sm: '',
            fl: '',
            wrw: '',
        })
        let data0 = [], data1 = [], data2 = [];
        for (let i in res.data) {
            if (res.data[i].sm == '水污染物') {
                data0.push(res.data[i].fl)
            } else if (res.data[i].sm == '固体废物') {
                data1.push(res.data[i].fl)
            } else if (res.data[i].sm == '噪声污染') {
                data2.push(res.data[i].fl)
            }
        }
        data0 = Array.from(new Set(data0))
        data1 = Array.from(new Set(data1))
        data2 = Array.from(new Set(data2))
        for (let j in data0) {
            this.fenleiDatashui.push({
                label: data0[j],
                value: data0[j]
            })
        }
        for (let x in data1) {
            this.fenleiDataguti.push({
                label: data1[x],
                value: data1[x]
            })
        }
        for (let y in data2) {
            this.fenleiDatazaosheng.push({
                label: data2[y],
                value: data2[y]
            })
        }
    },
    watch: {
        beizhu(newv, oldv) {
            console.log(newv)
            if (newv == '备注：null') {
                this.isbeizhu = false
            }
        }
    }
}
</script>

<style lang="less" scoped>
/deep/ .el-form {
    padding-left: 10px;

    .zhaiItem {
        width: 11%;
        margin-right: 0 !important;

        .el-form-item__content {
            width: 70%;
        }
    }
}

.nasui {
    margin-left: 20px;

    /deep/ .el-form-item__label {
        font-size: 20px;
        color: red;
    }
}

.nasuispan {
    font-size: 22px;
    color: red;
}

.tag {
    width: 550px;
    margin-left: 60%;
    white-space: normal;
    font-size: 14px;
    height: auto;
}
</style>
